﻿using ExcelMapper.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ExcelMapper
{
   public partial class ExcelQuery
    {
       private List<ExcelDocument> ExcelDocumentList;
       private Validation ExcelValidation;
       private ExcelFormat ExcelFormatValue;

       public ExcelQuery(ExcelDocument document)
       {
           this.ExcelDocumentList = new List<ExcelDocument>();
           this.ExcelValidation = new Validation();
           this.ExcelFormatValue = new ExcelFormat();

           if (document != null)
           {
               this.ExcelDocumentList.Add(document);
           }
           else
           {
               throw new Exception("ExcelDocument is null");
           }
       }

       public ExcelQuery(List<ExcelDocument> documentList)
       {
           this.ExcelDocumentList = new List<ExcelDocument>();
           this.ExcelValidation = new Validation();
           this.ExcelFormatValue = new ExcelFormat();

           if (documentList != null)
           {
               var repeateNames = documentList.GroupBy(s => s.Name)
                                       .Where(g => g.Count() > 1)
                                        .SelectMany(g => g)
                                        .ToList();

               if (repeateNames != null)
               {
                   throw new Exception("List<ExcelDocument> with repeated names");
               }
               else
               {
                   this.ExcelDocumentList.AddRange(documentList);
               }
           }
           else
           {
               throw new Exception("List<ExcelDocument> is null");
           }
       }


    }
}
